<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>首页</title>
  <link rel="stylesheet" href="./styles.css">
</head>
<body>
  
  <img src="./assets/index.png" alt="封面图片" class="cover-image">
  <h4 id="welcome-message">同学，欢迎您查看你的学生画像</h4>
  <div class="button-container">  
    <button onclick="goToGradesPage()">
      <img src="./assets/scoreQuery.jpg" alt="成绩查询">
    </button>
    <button onclick="goToLibraryPage()">
      <img src="./assets/accessLibrary.jpg" alt="图书馆进出">
    </button>
    <button onclick="goToBorrowPage()">
      <img src="./assets/borrowBook.jpg" alt="图书借阅" >
    </button>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
  <script>
    const studentId = '20220109100332'; // 示例学号，请替换为您实际的学号获取方式

    function getParameterByName(name, url) {
      if (!url) url = window.location.href;
      name = name.replace(/[$$]/g, '\\$&');
      var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
          results = regex.exec(url);
      if (!results) return null;
      if (!results[2]) return '';
      return decodeURIComponent(results[2].replace(/\+/g, ' '));
    }

    // 页面加载完成后获取用户姓名
    window.onload = function() {
      const userName = getParameterByName('userName'); // 获取姓名
      console.log(userName);

      if (userName) {
        document.getElementById('welcome-message').innerText = `${userName}同学，欢迎您查看你的学生画像`;
      } else {
        document.getElementById('welcome-message').innerText = `同学，欢迎您查看你的学生画像`;
      }
    };

    function goToGradesPage() {
      const url = `./grades.html?studentId=${studentId}`;
      window.location.href = url;
    }

    function goToBorrowPage() {
      const url = `./borrowed-books.html?studentId=${studentId}`;
      window.location.href = url;
    }

    function goToLibraryPage() {
      const url = `./library-access.html?studentId=${studentId}`;
      window.location.href = url;
    }
  </script>
</body>
</html>